'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:PersonnelJbtipCtrl
 * @description
 * # PersonnelJbtipCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('PersonnelJbtipCtrl', function ($scope, $location, localStorageService, openApi, Util, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
            // 底部付款方式选框添加
        $scope.param = {};
        $scope.timeUnitList = [{
            key: "天",
            value: "天"
        }, {
            key: "小时",
            value: "小时"
        }];
        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.overtimeApply;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if (!$scope.param.startDate) {
                Util.Toast("请选择加班起始日期");
                return;
            }
            if (!$scope.param.endDate) {
                Util.Toast("请选择加班截至日期");
                return;
            }
            if (!$scope.param.overtimeDays) {
                Util.Toast("请填写加班数量");
                return;
            }
            if (!Util.checkDays($scope.param.overtimeDays)) {
                Util.Toast("加班数量要为0.5的倍数");
                return;
            }

            if (!$scope.param.overtimeReason) {
                Util.Toast("请填写加班事由");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }

        $scope.chooseProject = function() {
            // 将列表的数据序列化存入缓存以便回来时候使用
            Util.savaParamForReview($scope.param, id);
            $location.path("project/chooseproject");
          };

        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                $scope.param.unit="小时";
                var data = localStorageService.get("projectinfo");
                localStorageService.remove("projectinfo");
                $scope.param = Object.assign({}, $scope.param, data);
            });
        };
        // 初始化
        init()
    });
